Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: voluntary exit #648

Merged
merged 19 commits into from
Jun 3, 2022
Merged

core: voluntary exit #648

merged 19 commits into from
Jun 3, 2022

Conversation

leolara
Copy link
Contributor

@leolara leolara commented Jun 1, 2022

Adds support for voluntary exits via a new DutyExit.

category: feature
ticket: #553

@codecov
Copy link

codecov bot commented Jun 1, 2022

Codecov Report

Merging #648 (e400958) into main (87c2054) will decrease coverage by 0.10%.
The diff coverage is 53.33%.

@@            Coverage Diff             @@
##             main     #648      +/-   ##
==========================================
- Coverage   55.23%   55.13%   -0.11%     
==========================================
  Files          98       98              
  Lines        9477     9652     +175     
==========================================
+ Hits         5235     5322      +87     
- Misses       3492     3560      +68     
- Partials      750      770      +20     
Impacted Files Coverage Δ
testutil/beaconmock/beaconmock.go 67.53% <0.00%> (-1.81%) ⬇️
core/bcast/bcast.go 31.66% <25.00%> (-2.43%) ⬇️
core/validatorapi/validatorapi.go 54.90% <50.87%> (+2.40%) ⬆️
core/sigagg/sigagg.go 58.67% <57.14%> (-0.21%) ⬇️
core/encode.go 55.88% <63.63%> (+1.49%) ⬆️
core/validatorapi/router.go 65.08% <75.00%> (+0.24%) ⬆️
core/types.go 43.24% <100.00%> (+0.77%) ⬆️
core/scheduler/scheduler.go 74.26% <0.00%> (-0.60%) ⬇️
cmd/run.go 100.00% <0.00%> (ø)
p2p/config.go 62.50% <0.00%> (ø)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 87c2054...e400958. Read the comment docs.

core/types.go Outdated
DutyProposer DutyType = 1
DutyAttester DutyType = 2
DutyRandao DutyType = 3
DutyVoluntaryExit DutyType = 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose we rename this to DutyExit, since there is only this type of exit duty, there are no non-voluntary or any other type of exit duty. This also aligns with the other duties above, which is just DutyProposer and DutyRandao instead of more verbose redundant versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fell comfortable with this, there will be other Exits in the code, could we ask for feedback to @OisinKyne @dB2510 @xenowits ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 100 to 104
ve := new(eth2p0.SignedVoluntaryExit)
err := json.Unmarshal(aggData.Data, ve)
if err != nil {
return errors.Wrap(err, "json decoding voluntary exit")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow above pattern of extracting this to core.DecodeExitAggSignedData

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if err == nil {
log.Info(ctx, "Voluntary exit successfully submitted to beacon node",
z.U64("epoch", uint64(ve.Message.Epoch)),
z.U64("validatorIndex", uint64(ve.Message.ValidatorIndex)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use snake case for json logging fields (see guidelines)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add the pubkey here: z.Any("pubkey", pubkey)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 96 to 102
ve := &eth2p0.SignedVoluntaryExit{
Message: &eth2p0.VoluntaryExit{
Epoch: 10,
ValidatorIndex: 10,
},
Signature: testutil.RandomEth2Signature(),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could extract this as testutil.RandomSignedVoluntaryExit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is too small to extract plus it would be used only here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 104 to 110
aggDataData, err := json.Marshal(ve)
require.NoError(t, err)

aggData := core.AggSignedData{
Data: aggDataData,
Signature: core.SigFromETH2(ve.Signature),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract this to core.EncodeExitAggSignedData

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return errors.New("cannot find validator", z.U64("ValidatorIndex", uint64(ve.Message.ValidatorIndex)))
}

pubKeyBytes, err := vs[ve.Message.ValidatorIndex].PubKey(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will panic if the map contains a different index.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can rename variable to eth2Pubkey

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done both things

Comment on lines 393 to 406
data, err := json.Marshal(ve)
if err != nil {
return nil
}

parSigDate := core.ParSignedData{
Data: data,
Signature: core.SigFromETH2(ve.Signature),
ShareIdx: c.shareIdx,
}

parsigSet := core.ParSignedDataSet{
pubKey: parSigDate,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use core.Encode...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 408 to 411
duty := core.Duty{
Type: core.DutyVoluntaryExit,
Slot: math.MaxInt64,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use slot 0, since a zero value in golang often means "unset" and slot 0 isn't a valid eth2 slot.

Copy link
Contributor

@corverroos corverroos Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or actually, we should probably convert the epoch into a slot (1st slot in the epoch) and use that. Just incase multiple exits are requested with different epochs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I do it but I will put a reference that it was your idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -33,7 +33,7 @@ const (
DomainBeaconAttester DomainName = "DOMAIN_BEACON_ATTESTER"
DomainRandao DomainName = "DOMAIN_RANDAO"
// DomainDeposit DomainName = "DOMAIN_DEPOSIT"
// DomainVoluntaryExit DomainName = "DOMAIN_VOLUNTARY_EXIT"
DomainVoluntaryExit DomainName = "DOMAIN_VOLUNTARY_EXIT"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can move this up to just below DomainRandao

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if err != nil {
return err
}
if len(vs) != 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do else if since it is part of the error handling/validator of the above call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed this code, so this `if len' is not anymore

@corverroos
Copy link
Contributor

Not sure the description of the PR is correct. This doesn't have anything to do with offline validators? This is just adding support for voluntary exit data...?

@@ -72,6 +77,7 @@ func (b Broadcaster) Broadcast(ctx context.Context, duty core.Duty,
z.U64("slot", uint64(att.Data.Slot)),
z.U64("target_epoch", uint64(att.Data.Target.Epoch)),
z.Hex("agg_bits", att.AggregationBits.Bytes()),
z.Any("pubkey", pubkey.String()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove .String() since z.Any does that automatically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 410 to 411
// By instructions of @corverroos I am putting an epoch into a field called Slot
// https://github.com/ObolNetwork/charon/pull/648#discussion_r886724647
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't seem very professional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to remove it, and you add the code in a commit under your name.

If this is a bad decision, that you or the company should be ashamed of, please let me know why we are taking it, when there are better alternatives.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, do you want me to remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Type: core.DutyVoluntaryExit,
// By instructions of @corverroos I am putting an epoch into a field called Slot
// https://github.com/ObolNetwork/charon/pull/648#discussion_r886724647
Slot: int64(ve.Message.Epoch),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant converting the epoch into the first slot of the epoch. not just using the epoch itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is not what you said, do you want to change it again?

Copy link
Contributor

@corverroos corverroos Jun 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please.

Note I said:

or actually, we should probably convert the epoch into a slot (1st slot in the epoch) and use that. Just incase multiple exits are requested with different epochs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so I revert it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@corverroos you are editing comments to change what you said

}
}

func RandomSignedVoluntaryExit(t *testing.T) *eth2p0.SignedVoluntaryExit {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t not required since not used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -376,3 +376,24 @@ func RandomUnsignedDataSet(t *testing.T) core.UnsignedDataSet {
RandomCorePubKey(t): unsigned,
}
}

func RandomVoluntaryExit(t *testing.T) *eth2p0.VoluntaryExit {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t not required since not used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it isn't used, so you do not need to include it, some random things require it, others don't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

t.Helper()

return &eth2p0.SignedVoluntaryExit{
Message: &eth2p0.VoluntaryExit{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can replace with RandomVoluntaryExit()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

core/encode.go Outdated
@@ -102,6 +102,22 @@ func EncodeAttestationParSignedData(att *eth2p0.Attestation, shareIdx int) (ParS
}, nil
}

// EncodeVoluntaryExitParSignedData encodes to json to pass between Go components losing typing,
// returns a ParSignedData that contains json.
// WARNING: using this method makes you lose Golang type safety features.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove unprofessional comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is unprofessional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting personal style disagreements into the code as comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a personal style, this is a statement of fact, that other contributors should be aware of.

If you think this decision is shameful, we should decide about why we are doing it this way, when there are easier ways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can find in Open Source software this type of comments very often, that using a method is dangerous for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@corverroos corverroos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with putting personal style disagreements into the code as comments.

@leolara
Copy link
Contributor Author

leolara commented Jun 2, 2022

| Not sure the description of the PR is correct. This doesn't have anything to do with offline validators? This is just adding support for voluntary exit data...?

The PR description is from the ticket from @OisinKyne

if you have a better description please change it.

@leolara
Copy link
Contributor Author

leolara commented Jun 2, 2022

@corverroos if you want to put something else in the Slot of the duty, please push it as a commit to this branch, I am confused about what you want there

@leolara
Copy link
Contributor Author

leolara commented Jun 2, 2022

@corverroos I have remove the WARNING comment and changed VoluntaryExit to Exit.

The epoch thing I don't understand please add a commit to the branch before merging.

Cheers!

@corverroos corverroos added the merge when ready Indicates bulldozer bot may merge when all checks pass label Jun 3, 2022
@obol-bulldozer obol-bulldozer bot merged commit 94e616b into main Jun 3, 2022
@obol-bulldozer obol-bulldozer bot deleted the leolara/voluntary-exit branch June 3, 2022 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge when ready Indicates bulldozer bot may merge when all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants